package com.qingzhuge.common.utils;

import com.alibaba.fastjson.JSON;

/**
 * @author : zero.xiao
 * @description :
 * @date : 2018/6/27 0027 上午 11:11
 * @modified :
 * @since :
 */
public class JsonUtil {
    /**
     * Object转成JSON数据
     */
    public static <T> String toJson(T object){
        if(object instanceof Integer || object instanceof Long || object instanceof Float ||
                object instanceof Double || object instanceof Boolean || object instanceof String){
            return String.valueOf(object);
        }
        return JSON.toJSONString(object);
    }

    /**
     * JSON数据，转成Object
     */
    public static  <T> T fromJson(String json, Class<T> clazz){
        return JSON.parseObject(json, clazz);
    }
}
